package com.lonely.order.enums;

import cn.hutool.core.lang.Assert;
import lombok.Getter;

import java.util.Arrays;
import java.util.Objects;

/**
 * 订单相关枚举
 *
 * @author fzzf
 */
public class OrderEnum {


    /**
     * 订单状态枚举
     */
    @Getter
    public enum OrderStatus {

        /**
         * 待接单
         */
        PENDING_ORDERS(0, "待接单"),

        /**
         * 待采购
         */
        TO_BE_PURCHASED(1, "待采购"),

        /**
         * 待发料
         */
        //PENDING_MATERIALS(2, "待发料"),

        /**
         * 裁剪中
         */
        CUTTING_IN_PROGRESS(3, "裁剪中"),

        /**
         * 车缝中
         */
        IN_THE_CAR_SEAM(4, "车缝中"),

        /**
         * 尾部中
         */
        IN_THE_TAIL(5, "尾部中"),

        /**
         * 待收货(客户)
         */
        PENDING_RECEIPT_CUSTOMER(6, "待收货(客户)"),

        /**
         * 已完成
         */
        COMPLETED(7, "已完成"),

        /**
         * 已废除
         */
        REPEALED(8, "已废除");

        private final int status;

        private final String desc;

        OrderStatus(int status, String desc) {
            this.status = status;
            this.desc = desc;
        }

        /**
         * 根据订单状态名称获取对应的状态
         *
         * @param statusName
         * @return
         */
        public static int getStatusByStatusName(String statusName) {
            OrderStatus orderStatus = Arrays.stream(OrderStatus.values()).filter(x -> Objects.equals(x.getDesc(), statusName)).findFirst().orElse(null);
            Assert.notNull(orderStatus, String.format("订单状态:%s 对应枚举不存在", statusName));
            return Objects.requireNonNull(orderStatus).getStatus();
        }
    }


    /**
     * 订单类型枚举
     */
    @Getter
    public enum OrderType {
        /**
         * CMT
         */
        CMT(0, "CMT"),

        /**
         * FOB
         */
        FOB(1, "FOB"),

        /**
         * ODM
         */
        ODM(2, "ODM");


        private final int type;

        private final String desc;

        OrderType(int type, String desc) {
            this.type = type;
            this.desc = desc;
        }

        /**
         * 根据订单类型获取对应的枚举
         *
         * @param type
         * @return
         */
        public static OrderType getInstanceByType(Integer type) {
            return Arrays.stream(OrderType.values()).filter(x -> Objects.equals(x.getType(), type)).findFirst().orElse(null);
        }

        /**
         * 根据订单类型名称获取对应的枚举
         *
         * @param desc
         * @return
         */
        public static OrderType getInstanceByDesc(String desc) {
            return Arrays.stream(OrderType.values()).filter(x -> Objects.equals(x.getDesc(), desc)).findFirst().orElse(null);
        }
    }


    /**
     * 订单备货枚举
     */
    @Getter
    public enum OrderStockType {

        /**
         * 普通备货
         */
        REGULAR_STOCKING(1, "普通备货"),

        /**
         * 特殊备货
         */
        SPECIAL_STOCKING(2, "特殊备货"),

        /**
         * JIT
         */
        JIT(3, "JIT"),


        /**
         * 尾货
         */
        TAIL_GOODS(4, "尾货"),


        /**
         * 自主备货
         */
        SELF_STOCKING(5, "自主备货"),


        /**
         * 其他
         */
        OTHER(6, "其他"),


        ;


        private final int type;

        private final String desc;

        OrderStockType(int type, String desc) {
            this.type = type;
            this.desc = desc;
        }

        /**
         * 根据订单备货类型获取对应的枚举
         *
         * @param type
         * @return
         */
        public static OrderStockType getInstanceByType(Integer type) {
            return Arrays.stream(OrderStockType.values()).filter(x -> Objects.equals(x.getType(), type)).findFirst().orElse(null);
        }

        /**
         * 根据订单备货名称获取对应的枚举
         *
         * @param desc
         * @return
         */
        public static OrderStockType getInstanceByDesc(String desc) {
            return Arrays.stream(OrderStockType.values()).filter(x -> Objects.equals(x.getDesc(), desc)).findFirst().orElse(null);
        }
    }


    /**
     * 是否首单枚举
     */
    @Getter
    public enum IsFirstOrder {

        /**
         * 首单
         */
        FIRST_ORDER(1, "首单"),

        /**
         * 返单
         */
        RETURN_ORDER(2, "返单"),
        ;


        private final int type;

        private final String desc;

        IsFirstOrder(int type, String desc) {
            this.type = type;
            this.desc = desc;
        }

    }


    /**
     * 分单状态枚举
     */
    @Getter
    public enum SplitStatus {

        /**
         * 未分单
         */
        UNCIVILIZED_ORDERS(1, "未分单"),

        /**
         * 已分单
         */
        SEPARATED_ORDERS(2, "已分单"),
        ;


        private final int type;

        private final String desc;

        SplitStatus(int type, String desc) {
            this.type = type;
            this.desc = desc;
        }

    }


    /**
     * 分单类型枚举
     */
    @Getter
    public enum SplitType {

        /**
         * 普通分单
         */
        NORMAL("normal"),

        /**
         * 尾部分单
         */
        TAIL("tail"),
        ;


        private final String type;


        SplitType(String type) {
            this.type = type;
        }
    }


    /**
     * 订单来源枚举
     */
    @Getter
    public enum OrderSourceEnum {

        /**
         * shein接口
         */
        SHEIN(1),

        /**
         * 本地
         */
        LOCAL(2),
        ;

        /**
         * 订单来源
         */
        private final int orderSource;

        OrderSourceEnum(int orderSource) {
            this.orderSource = orderSource;
        }
    }
}
